function new_att(textareaid) {
    Wind.use("artDialog","iframeTools",function(){
        art.dialog.open(GV.DIMAUB+'statics/grid.html', {
        title:'增加属性',
		id:'new_att',
        width: '50%',
        height: '500px',
        lock: true,
        fixed: true,
        background:"#CCCCCC",
        opacity:0,
        ok: function() {
			add_att.apply(this,[this,textareaid]);
		},
        cancel: true
    });
    });
}

function draw(json){
	$.each(json,function(i,e){
		content += att_grid(JSON.stringify(e));	
	})
	$('#content').append(content);
}


function add_att(uploadid,returnid) {
    var d = uploadid.iframe.contentWindow;
    var in_content = d.$("#att-status").html().substring();
    if (in_content == '') return false;	
    $('#' + returnid).append(att_grid(in_content));
	$("#submit").trigger('click');
}

function att_grid(att_json){
	var att_obj = JSON.parse(att_json);
	var att_choixs = '';
	$.each(att_obj.choix,function(i,e){
		att_choixs +='<span class="label label-info">'+att_obj.choix[i].name+'</span> : <span class="badge badge-success">减:'+att_obj.choix[i].price+'</span><br/>';
	});
	var ids = parseInt(Math.random() * 10000);
    var str = '<tr id="'+ids+'"><td class="hidden">'+att_json+'</td><td width="15%" class="xcenter">'+att_obj.title+'</td><td width="45%">'+att_choixs+'</td><td><a class="btn" href=\"javascript:modify_att('+ids+')\">修改</a></td><td><a class="btn" href=\"javascript:remove_div('+ids+')\">移除</a></td><td><a class="btn" href=\"javascript:move_up('+ids+')\">上移</a><a class="btn" href=\"javascript:move_down('+ids+')\">下移</a></td></tr>';	
	return str;	
}

//移除ID
function remove_div(id) {
    $('#' + id).remove();
}

function move_up(id) {
	var up = $("#"+id).prev("tr");
	up.insertAfter($("#"+id));	
}

function move_down(id) {
    var up = $("#"+id).next("tr");
	up.insertBefore($("#"+id));
}

function modify_att(ids) {
	var json =  $("#"+ids).find(".hidden").html();	
	 Wind.use("artDialog","iframeTools",function(){
		art.dialog.data('json',json); // 存储数据  
		art.dialog.open(GV.DIMAUB+'statics/grid2.html', {
			title:'修改属性',
			id:'modify_att',
			width: '50%',
			height: '500px',
			lock: true,
			fixed: true,
			background:"#CCCCCC",
			opacity:0,
			ok: function() {
				change_att.apply(this,[this,ids]);
			},
			cancel: true
		});
    });
}

function change_att(uploadid,returnid){
    var d = uploadid.iframe.contentWindow;
    var att_json = d.$("#att-status").html().substring();	
    if (att_json == '') return false;	
	
	var att_obj = JSON.parse(att_json);
	var att_choixs = '';
	$.each(att_obj.choix,function(i,e){
		att_choixs +='<span class="label label-info">'+att_obj.choix[i].name+'</span> : <span class="badge badge-success">减:'+att_obj.choix[i].price+'</span><br/>';
	});	
   	$("#"+returnid+" td:eq(0)").html(att_json);
	$("#"+returnid+" td:eq(1)").html(att_obj.title);
	$("#"+returnid+" td:eq(2)").html(att_choixs);
	$("#submit").trigger('click');
}